<?php
/**
 * Created by PhpStorm.
 * User: Jerry
 * Date: 2016/12/21
 * Time: 9:31
 */

namespace SDXApi\Model;


use Think\Model;

/**
 * Class HomeTemplateStencilModel
 * @package SDXApi\Model
 */
class HomeTemplateStencilNewModel extends Model
{

	/**
	 * @var string
	 */
	protected $tableName = 'home_template_stencil';


    /**
     * @author Jerry
     * @param $template_id
     * @param int $pageNumber
     * @param int $pageSize
     * @return mixed
     */
	public function find_template_stencil_by_template_id($template_id, $pageNumber = 1, $pageSize = 0)
	{
        $group_id = I('get.group_id', 6, 'int');

        $pageArr = show_page($pageSize, $pageNumber, 5);

        if ($group_id == 6) {
            if ($pageNumber == 1) {
                $limitpage = 8;
                $firstpage = $pageArr['firstpage'];
            } else {
                $limitpage = 5;
                $firstpage = $pageArr['firstpage'] + 3;
            }
        } else {
            $limitpage = 5;
            $firstpage = $pageArr['firstpage'];
        }

		$where = array(
			'template_id'	=>	$template_id,
		);

		return $this->where($where)->order('sort desc')->limit($firstpage . ',' . $limitpage)->select();
	}

    /**
     * @author Jerry
     * @param $template_id
     * @return mixed
     */
    public function findTemplateStencilCountNumberByTemplateId($template_id)
    {
        $where = array(
            'template_id'	=>	$template_id,
        );

        return $this->where($where)->count();
    }
}